{#级别管理界面#}
{% extends 'laout.html' %}
{% block content %}
{#导入权限判断按钮是否显示文件    #}
{% load permission %}

     <div style="margin-bottom: 5px" class="clearfix">
{#        <a href="{% url 'level_add' %}" class="btn btn-success">#}
{#            <span class="glyphicon glyphicon-plus-sign"></span>#}
{#            新建</a>#}
        {#代替以上代码： 导入simple_tag自定义模板功能 解决权限控制按钮问题  传值：request ; 按钮url的name属性  #}
        {% add_permission request 'level_add' %}
     </div>
    <table class="table table-striped table-bordered">

    <div class="row">
        <thead>
            <tr >
                <th class="col-lg-3">id</th>
                <th class="col-lg-3">标题</th>
                <th class="col-lg-3">折扣</th>
                {# 防止没功能时显示空白窗格          #}
                {% if request|has_permission:"level_edit,level_delete" %}
                    <th class="col-lg-3">操作</th>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for i in level_show %}
                <tr>
                    <td>{{ i.id }}</td>
                    <td>{{ i.title }}</td>
                    <td>{{ i.percent }}%</td>
                    {% if request|has_permission:"level_edit,level_delete" %}
                        <td>
                            {# a标签+按钮样式，实现按钮   #}
{#                            <a href="{% url 'level_edit' pk=i.id %}" class="btn btn-primary btn-xs">编辑</a>#}
{#                            <span>|</span>#}
{#                            <a href="{% url 'level_delete' pk=i.id %}" class="btn btn-danger btn-xs">删除</a>#}
                            {% edit_permission request 'level_edit' pk=i.id %}
                            {% delete_url_permission request "level_delete" pk=i.id %}
                        </td>
                    {% endif %}
                </tr>
            {% endfor %}
        </tbody>
    </div>
    </table>

{% endblock %}
